{%extends 'list_detail.html' %}
{%block head%}
    <script type="text/javascript">
        $(function () {

		var $to_x = $('#show_count').offset().top;
		var $to_y = $('#show_count').offset().left;

		// click/this: id等级比class高,用id的话获取只能是第一个有效!!没法区分id之间的关系
		$('.add_goods').click(function(){
        var $add_x = $(this).offset().top;
		var $add_y = $(this).offset().left;

		var goods_id = $(this).parents('.operate').find('#goods_id').text();
{#		alert(goods_id)#}

			$.get('/cart/add'+goods_id+'_'+1+'/',function (data) {
                if (data.islogin == 0){
                     location.href='/user/login.html/';
                    return;
                }else{
                    $('#show_count').html(data.count);
                }
                $(".add_jump").css({'left':$add_y,'top':$add_x,'display':'block'})
            .animate({'left': $to_y+7, 'top': $to_x+7},"fast", function() {
                $(".add_jump").fadeOut('fast');
            });
            })

			});
})
        </script>


{%endblock head%}


    {%block goods_div%}


		<div class="r_wrap fr clearfix">
			<div class="sort_bar">
				<a href="/list{{typeinfo.id}}_1_1"
                   {% if sort == "1" %}
                   class="active"
                    {% endif %}
                >默认</a>
				<a href="/list{{typeinfo.id}}_1_2"
                   {% if sort == "2" %}
                   class="active"
                    {% endif %}
                >价格</a>
				<a href="/list{{typeinfo.id}}_1_3"
                   {% if sort == "3" %}
                   class="active"
                    {% endif %}
                >人气</a>
			</div>

			<ul class="goods_type_list clearfix">
                {% for g in pages %}
				<li>
					<a href="/detail{{ g.id }}" target="_blank"><img src="/static/{{g.gpic}}"></a>
					<h4><a href="/detail{{ g.id }}" target="_blank">{{ g.title }}</a></h4>
                    <div class="operate">
                        <div id="goods_id" style="display: none" >{{ g.id }}</div>
						<span class="prize">￥{{g.gprice}}</span>
						<span class="unit">{{g.gunit}}</span>
						<a href="javascript:;" class="add_goods"  title="加入购物车"></a>
					</div>
				</li>
                {% endfor %}
            </ul>



            <div class="add_jump"></div>




			<div class="pagenation">
                <a href="/list{{ typeinfo.id }}_1_{{ sort }}/">首页</a>
                {%if pages.has_previous%}
				    <a href="/list{{ typeinfo.id }}_{{ pages.number|add:-1 }}_{{ sort }}"><上一页</a>
                {% else %}
                    <a href="" class="active"><上一页</a>
                {% endif %}
                {% for index in pages.paginator.page_range %}
                    {%if index == pages.number%}
				<a href="#" class="active">{{index}}</a>
                        {% else %}
				<a href="/list{{ typeinfo.id }}_{{ index }}_{{ sort }}/">{{ index }}</a>
				    {% endif %}
                {% endfor %}

            {% if pages.has_next %}
				<a href="/list{{ typeinfo.id }}_{{ pages.number|add:1 }}_{{ sort }}">下一页></a>
                {% else %}
                <a href="" class="active">下一页></a>
            {% endif %}
             <a href="/list{{ typeinfo.id }}_{{ pages.paginator.num_pages }}_{{ sort }}/">末页</a>
			</div>
		</div>




    {%endblock goods_div%}